package com.mianshi;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class rongyao3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String name = in.nextLine();
        Set<String> set = new HashSet<>();
        set.add(name);
        int num = Integer.parseInt(in.nextLine());
        for(int i = 0; i < num; i++){
            String str = in.nextLine();
            String[] arr = str.split(",");
            boolean flag = false;
            for(int j = 0; j < arr.length; j++){
                String s = arr[j];
                if(set.contains(s)){
                    flag = true;
                    break;
                }
            }
            if(flag){
                for(String item : arr){
                    set.add(item);
                }
            }
        }
        System.out.println(set.size());
    }
}
